<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace App\Controller;

use App\Model\UserToken;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Contract\ResponseInterface;
use Psr\Container\ContainerInterface;

abstract class AbstractController
{
    /**
     * @Inject
     * @var ContainerInterface
     */
    protected $container;

    /**
     * @Inject
     * @var RequestInterface
     */
    protected $request;

    /**
     * @Inject
     * @var ResponseInterface
     */
    protected $response;

    /**
     * 接口输出响应统一格式
     * @param int $code
     * @param string $msg
     * @param array $data
     * @return \Psr\Http\Message\ResponseInterface
     */
    protected function output($code=0,$msg='',$data=[]){
        $data = [
            'code'=>$code,
            'msg'=>$msg,
            'data'=>$data
        ];
        return $this->response->json($data);
    }

    public function getUserInfo(){
        $token = $this->request->getHeader('token');
        $con = UserToken::checkUser($token[0]);
        return ['uid'=>$con['data']['uid'],'token'=>$token[0]];
    }


}
